package com.gukun.springboot.tdengine.controller;

import com.gukun.springboot.tdengine.domain.common.CommonResult;
import com.gukun.springboot.tdengine.domain.delete.DeleteLog;
import com.gukun.springboot.tdengine.domain.delete.DeleteTask;
import com.gukun.springboot.tdengine.service.delete.DeleteLogService;
import com.gukun.springboot.tdengine.service.delete.DeleteTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 4998
 * @createDate: 2025-06-04  14:42
 * @description:
 */
@RestController
@RequestMapping("/api/tdengine/delete/")
public class DeleteTaskController {
    @Autowired
    private DeleteTaskService deleteTaskService;

    @Autowired
    private DeleteLogService deleteLogService;

    @PostMapping("list")
    public CommonResult<List<DeleteTask>> list(@RequestBody DeleteTask deleteTask) throws Exception {
        return CommonResult.success(deleteTaskService.list(deleteTask));
    }

    @PostMapping("initDefaultTask")
    public CommonResult<Boolean> initDefaultTask(@RequestBody DeleteTask deleteTask) throws Exception {
        return CommonResult.success(deleteTaskService.initDefaultTask(deleteTask));
    }

    @PostMapping("saveOrUpdate")
    public CommonResult<Boolean> saveOrUpdate(@ModelAttribute DeleteTask deleteTask) throws Exception {
        return CommonResult.success(deleteTaskService.saveOrUpdate(deleteTask));
    }

    @GetMapping("deleteById")
    public CommonResult<Boolean> deleteById(@RequestParam String id) throws Exception {
        return CommonResult.success(deleteTaskService.deleteById(id));
    }

    @GetMapping("start")
    public CommonResult<Boolean> start(@RequestParam String id) throws Exception {
        return CommonResult.success(deleteTaskService.start(id));
    }

    @GetMapping("stop")
    public CommonResult<Boolean> stop(@RequestParam String id) throws Exception {
        return CommonResult.success(deleteTaskService.stop(id));
    }

    @GetMapping("listDeleteLog")
    public CommonResult<List<DeleteLog>> listDeleteLog(@RequestParam String taskId){
        return CommonResult.success(deleteLogService.listDeleteLog(taskId));
    }

}
